package com.WJY.controller;

import com.WJY.pojo.Book;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class BookController {

    // 1.实现跳转
    @RequestMapping("/t1")
    public String t1() {
        return "WEB-INF/jsp/aaa.jsp";
    }

    // 2.返回字符串
    @RequestMapping(value = "/t2", produces = "application/json;charset=utf-8")
    @ResponseBody   //页面展示返回值本身
    public String t2() {
        return "真是只聪明的小可爱";
    }

    // 3.返回对象
    @RequestMapping(value = "/t3", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Book t3(Book book) {
        return book;
    }

    @RequestMapping(value = "/t03",produces = "application/json;charset=utf-8")
    @ResponseBody
    public Book t03() {
        return new Book(3,"Java","张三","广东省");
    }
    // 4.接收普通参数
    @RequestMapping(value = "/t4", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String t4(@RequestParam("username") String name, int age) {
        return "名为" + name + "的女士今年" + age + "岁了";
    }

    // 5.接收对象
    @RequestMapping(value = "/t5", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Book t5(Book book) {
        return book;
    }

    // 6.接收json的集合
    @RequestMapping("/t6")
    @ResponseBody
    public List<Book> t6(@RequestBody List<Book> list) {
        System.out.println(list);
        return list;
    }
}
